<?php

/**
 * This is the model class for table "issue_statuses".
 *
 * The followings are the available columns in table 'issue_statuses':
 * @property integer $id
 * @property string $name
 * @property integer $is_closed
 * @property integer $is_default
 * @property integer $position
 * @property integer $default_done_ratio
 *
 * The followings are the available model relations:
 * @property Issues[] $issues
 * @property Workflows[] $workflows
 * @property Workflows[] $workflows1
 */
class IssueStatus extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return IssueStatuses the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'issue_statuses';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('is_closed, is_default, position, default_done_ratio', 'numerical', 'integerOnly'=>true),
            array('name', 'length', 'max'=>30),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, is_closed, is_default, position, default_done_ratio', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'issues' => array(self::HAS_MANY, 'Issue', 'status_id'),
            'workflows' => array(self::HAS_MANY, 'Workflow', 'old_status_id'),
            'workflows1' => array(self::HAS_MANY, 'Workflow', 'new_status_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'name' => 'Name',
            'is_closed' => 'Is Closed',
            'is_default' => 'Is Default',
            'position' => 'Position',
            'default_done_ratio' => 'Default Done Ratio',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('is_closed',$this->is_closed);
        $criteria->compare('is_default',$this->is_default);
        $criteria->compare('position',$this->position);
        $criteria->compare('default_done_ratio',$this->default_done_ratio);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}